package com.kuaiprint.fragment;

import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ListView;

import com.kuaiprint.adapter.ListViewAdapter;
import com.kuaiprint.bean.PrintStoreBean;
import com.kuaiprint.main.ItemChooseActivity;
import com.kuaiprint.main.R;
import com.kuaiprint.main.SubmitActivity;

public class PrintStoreFragment extends Fragment{

	

	private ListView printListView;
	private List<PrintStoreBean> storeList;
	private ListViewAdapter listViewAdapter;
	private LinearLayout printDaying;
	private LinearLayout printFuying;
	private LinearLayout printGongchengtu;
	private LinearLayout printZhuangding;
	private LinearLayout printPenghui;
	private LinearLayout printXiezheng;
	private LinearLayout printHuace;
	private LinearLayout printMore;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,  
            Bundle savedInstanceState)  
    {  
        View view = inflater.inflate(R.layout.printstore_fragment, container, false);
        initView(view);
   
       setClickListener();
		return view;
    }
	
	
	
	 
	 
	 private void     setClickListener() {
		// TODO Auto-generated method stub
		 printMore.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent =new Intent();
				intent.setClass(getActivity(), ItemChooseActivity.class);
				startActivity(intent);
			}
		});
	}





	private void initView(View view) {
		// TODO Auto-generated method stub

	      printDaying = (LinearLayout) view.findViewById(R.id.print_daying);
	      printFuying = (LinearLayout) view.findViewById(R.id.print_fuying);
	      printHuace = (LinearLayout) view.findViewById(R.id.print_huace);
	      printMore = (LinearLayout) view.findViewById(R.id.print_more);     
	      printXiezheng = (LinearLayout) view.findViewById(R.id.print_xiezheng);
	      printPenghui = (LinearLayout) view.findViewById(R.id.print_penghui);
	      printZhuangding = (LinearLayout) view.findViewById(R.id.print_zhuangding);
	      printGongchengtu = (LinearLayout) view.findViewById(R.id.print_gongchengtu);
	      
	      
	        printListView = (ListView) view.findViewById(R.id.printstore_listview);
	        
	        storeList = new ArrayList<PrintStoreBean>();
	        for(int i = 0 ;i<10 ;i++)
	        {
	        	storeList.add(new PrintStoreBean(i, "打印店"+i, "", "",""));
	        }
	        listViewAdapter =new ListViewAdapter(getActivity(), storeList); 
	        printListView.setAdapter(listViewAdapter);
	        fixListViewHeight(printListView);
	}





	public void fixListViewHeight(ListView listView) {   
	        // 如果没有设置数据适配器，则ListView没有子项，返回。  
		 ListViewAdapter listAdapter = (ListViewAdapter) listView.getAdapter();  
	        int totalHeight = 0;   
	        if (listAdapter == null) {   
	            return;   
	        }   
	        for (int index = 0, len = listAdapter.getCount(); index < len; index++) {     
	            View listViewItem = listAdapter.getView(index , null, listView);  
	            // 计算子项View 的宽高   
	            listViewItem.measure(0, 0);    
	            // 计算所有子项的高度和
	            totalHeight += listViewItem.getMeasuredHeight();    
	        }   
	   
	        ViewGroup.LayoutParams params = listView.getLayoutParams();   
	        // listView.getDividerHeight()获取子项间分隔符的高度   
	        // params.height设置ListView完全显示需要的高度    
	        params.height = totalHeight+ (listView.getDividerHeight() * (listAdapter.getCount() - 1));   
	        listView.setLayoutParams(params);   
	    }   
}
